package com.lzy.mall.product.controller;


import cn.hutool.core.collection.CollUtil;
import com.lzy.mall.common.utils.PageUtils;
import com.lzy.mall.common.utils.ResultUtils;
import com.lzy.mall.product.entity.PmsAttrAttrgroupRelation;
import com.lzy.mall.product.service.PmsAttrAttrgroupRelationService;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 属性&属性分组关联(PmsAttrAttrgroupRelation)表控制层
 *
 * @author lzy
 * @since 2021-08-25 11:41:08
 */
@RestController
@RequestMapping("attrattrgrouprelation")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class PmsAttrAttrgroupRelationController {

    private final PmsAttrAttrgroupRelationService relationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:attrattrgrouprelation:list")
    public ResultUtils list(@RequestParam Map<String, Object> params){
        PageUtils page = relationService.queryPage(params);

        return ResultUtils.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("product:attrattrgrouprelation:info")
    public ResultUtils info(@PathVariable("id") Long id){
        PmsAttrAttrgroupRelation attrAttrgroupRelation = relationService.getById(id);

        return ResultUtils.ok().put("attrAttrgroupRelation", attrAttrgroupRelation);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:attrattrgrouprelation:update")
    public ResultUtils update(@RequestBody PmsAttrAttrgroupRelation attrAttrgroupRelation){
        relationService.updateById(attrAttrgroupRelation);

        return ResultUtils.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:attrattrgrouprelation:delete")
    public ResultUtils delete(@RequestBody Long[] ids){
        relationService.removeByIds(CollUtil.toList(ids));

        return ResultUtils.ok();
    }
}
